]> git.r.bdr.sh - rbdr/map/blame - Map/Presentation/Complex Components/MapRender/MapRenderView.swift
Address the lint warnings
[rbdr/map] / Map / Presentation / Complex Components / MapRender / MapRenderView.swift
CommitLineData
be897af3
RBR
1// Copyright (C) 2024 Rubén Beltrán del Río
2
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see https://map.tranquil.systems.
77d0155b 15import Combine
5e8ff485
RBR
16import CoreData
17import CoreGraphics
18import SwiftUI
19
20struct MapRenderView: View {
21
e2c37ac1 22 @Binding var document: MapDocument
fdb4633d 23 @Binding var evolution: StageType
e2c37ac1 24
fdb4633d
RBR
25 var stage: Stage {
26 Stage.stages(evolution)
27 }
75a0e450 28
e2c37ac1
RBR
29 var parsedMap: ParsedMap {
30 MapParser.parse(content: document.text)
31 }
5e8ff485 32
e2c37ac1
RBR
33 let mapSize = Dimensions.mapSize
34 let padding = Dimensions.mapPadding
5e8ff485 35
fdb4633d 36 let lineWidth = CGFloat(0.5)
5e8ff485 37 let vertexSize = CGSize(width: 25.0, height: 25.0)
e2c37ac1
RBR
38
39 var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in }
5e8ff485 40
5e8ff485
RBR
41 var body: some View {
42 ZStack(alignment: .topLeading) {
43
44 Path { path in
45 path.addRect(
46 CGRect(
47 x: -padding, y: -padding, width: mapSize.width + padding * 2,
77d0155b 48 height: mapSize.height + padding * 4))
fdb4633d 49 }.fill(.white)
5e8ff485
RBR
50
51 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
52 MapAxes(
fdb4633d
RBR
53 mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
54 MapEdges(
55 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
56 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
e2c37ac1
RBR
57 MapVertices(
58 mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
59 onDragVertex: onDragVertex)
5e8ff485
RBR
60 MapOpportunities(
61 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
62 opportunities: parsedMap.opportunities)
e2c37ac1
RBR
63 MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
64 opaque: true
65 ).opacity(0.1)
fdb4633d
RBR
66 MapNotes(
67 mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
e2c37ac1
RBR
68 }.offset(x: padding, y: padding).frame(
69 width: mapSize.width + 2 * padding,
77d0155b 70 height: mapSize.height + 2 * padding, alignment: .topLeading
e2c37ac1 71 )
5e8ff485
RBR
72 }
73}
74
e2c37ac1
RBR
75#Preview {
76 MapRenderView(
77 document: Binding.constant(MapDocument(text: "")),
78 evolution: Binding.constant(StageType.general)
79 )
5e8ff485 80}